package com.heima.admin.v1.controller;

import com.heima.admin.entity.AdChannel;
import com.heima.admin.service.AdChannelService;
import com.heima.common.dtos.PageResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.admin.dtos.ChannelPageDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@Api(tags = "频道管理" )
@RestController
@Slf4j
public class ChannelController {

    @Autowired
    private AdChannelService channelService;

    @ApiOperation("频道列表分页查询")
    @PostMapping("/api/v1/channel/list")
    public PageResult<AdChannel> list(@RequestBody ChannelPageDTO dto,
                                      @RequestHeader(value = "userId", required = false)Integer userId){
        log.info("---------------------------->userId:{}", userId);
        return channelService.pageQuery(dto);
    }

    @GetMapping("/api/v1/channel/channels")
    public ResponseResult<List<AdChannel>> listAll(){
        List<AdChannel> list = channelService.list();
        return ResponseResult.ok(list);
    }

}
